package structure.set.basic.tree;

import structure.bbst.rb.BinaryTree;
import structure.bbst.rb.RedBlackTree;

import java.util.Comparator;

/**
 * 项目名称: god
 * 包 名 称: com.set.basic.tree
 * 类 名 称: MyTreeSet
 * 类 描 述: TODO
 * 创建时间: 2020/6/14 4:17 下午
 * 创 建 人: Justice
 */
public class MyTreeSet<E> implements MySet2<E> {
    private RedBlackTree<E> tree;

    public MyTreeSet() {
        this(null);
    }

    public MyTreeSet(Comparator<E> comparator) {
        tree = new RedBlackTree<E>(comparator);
    }

    public int size() {
        return tree.size();
    }

    public boolean isEmpty() {
        return tree.isEmpty();
    }

    public void clear() {
        tree.clear();
    }

    public boolean contains(E element) {
        return tree.contains(element);
    }

    public void add(E element) {
        tree.add(element);
    }

    public void remove(E element) {
        tree.remove(element);
    }

    public void traversal() {
        tree.inOrder(new BinaryTree.Visitor<E>() {
            @Override
            protected boolean visit(E element) {
                System.out.println(element);
                return false;
            }
        });
    }
}
